Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming
Errors within a method
If a method needs to identify that it was unable to perform its action, the method can inform the caller by using an output or return parameter, setting a public data member, or using some other mechanism. For example, if the method has a return value (it's not a
VOIDmethod) the method might set the return value to the Unknown value (?), to indicate a failure. The caller of the method can test for this value and respond appropriately.If a statement within the method raises
ERROR(for example, aFINDstatement fails) the existing 4GL error functionality occurs. This means that if the statement hasNO-ERRORspecified for it, the error message is passed to theERROR-STATUSsystem handle and the next statement executes. The application can use theERROR-STATUSsystem handle to determine the error that occurred and respond appropriately. If the statement does not haveNO-ERRORspecified for it, Progress displays the error message to the default output device and breaks out of the inner most block, conforming to the options specified in anyONERRORphrase associated with the block.The following examples show how a method from some class can propagate a failure status to its caller and respond to a statement raising
ERROR:
The following numbered notes apply to the numbered code in the previous examples,
Test.clsandCaller.p:
Note: If the- If the
FINDstatement fails to locate a record, it raisesERRORand writes an error message to theERROR-STATUSsystem handle.FINDstatement did not haveNO-ERRORspecified, an error in the statement would cause any enclosingDOblock in the caller to end. If this happened,oAddress, and henceszAddress, could not be set and handled as expected, but this example handles it.- The application checks to see if the record was found and sets the output value appropriately. If a record is not found,
oAddressremains set to the Unknown value (?) to indicate an error.- In the caller, either an error raised by the
FINDstatement or missing data incustomersetsoAddressto the Unknown value (?) that signals the caller throughszAddressto proceed accordingly.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |